package com.ruoyi.app.fragment

import com.hjq.toast.ToastUtils
import com.ruoyi.app.R
import com.ruoyi.app.activity.LogsActivity
import com.ruoyi.app.adapter.BannerHolderCreator
import com.ruoyi.app.adapter.WorkManageAdapter
import com.ruoyi.app.databinding.FragmentWorkBinding
import com.ruoyi.app.model.entity.BannerEntity
import com.ruoyi.code.base.BaseBindingFragment

class WorkFragment : BaseBindingFragment<FragmentWorkBinding>() {

    companion object {
        @JvmStatic
        fun newInstance() = WorkFragment()
    }

    val adapter: WorkManageAdapter by lazy {
        WorkManageAdapter()
    }

    override fun initView() {
        val data = ArrayList<BannerEntity>()
        data.add(BannerEntity(R.mipmap.banner01, ""))
        data.add(BannerEntity(R.mipmap.banner02, ""))
        data.add(BannerEntity(R.mipmap.banner03, ""))
        val holderCreator = BannerHolderCreator()
        binding.xbanner.setBannerData(data, holderCreator)
    }

    override fun initData() {
        val data = ArrayList<BannerEntity>()
        data.add(BannerEntity(R.mipmap.icon_info_nicheng, "用户管理"))
        data.add(BannerEntity(R.mipmap.icon_info_jiaose, "角色管理"))
        data.add(BannerEntity(R.mipmap.icon_work_menu, "菜单管理"))
        data.add(BannerEntity(R.mipmap.icon_work_bumeng, "部门管理"))
        data.add(BannerEntity(R.mipmap.icon_work_gangwei, "岗位管理"))
        data.add(BannerEntity(R.mipmap.icon_work_field, "字典管理"))
        data.add(BannerEntity(R.mipmap.icon_work_setting, "参数设置"))
        data.add(BannerEntity(R.mipmap.icon_work_gonggao, "通知公告"))
        data.add(BannerEntity(R.mipmap.icon_work_rizhi, "日志管理"))

        adapter.setNewInstance(data)
        binding.recyclerview.adapter = adapter
        adapter.setOnItemClickListener { adapter, _, position ->
            var bannerEntity: BannerEntity = adapter.data.get(position) as BannerEntity
            if (bannerEntity.title == "日志管理") {
                LogsActivity.startActivity(requireContext())
            } else {
                ToastUtils.show("模块建设中~" + bannerEntity.title)
            }
        }
    }

}